package com.oracle.applicaiton.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.oracle.applicaiton.feign.MemberFeign;
import com.oracle.applicaiton.vo.MemberVo;
import com.oracle.application.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author bug制造者
 * @ClassName MemberController.java
 * @createTime 2021年07月08日 15:13:00
 * @Description
 */
@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private MemberFeign memberFeign;

    @GetMapping("/verifyEmail")
    @HystrixCommand(fallbackMethod = "fallbackVerifyEmail")
    public R verifyEmail(@RequestParam(name = "email") String email){
        System.out.println("没问题");
        return memberFeign.verifyEmail(email);
    }

    public R fallbackVerifyEmail(String email){
        return new R(404, "服务器繁忙，请稍后再试", null);
    }

    @PostMapping("/registerMember")
    @HystrixCommand(fallbackMethod = "fallBackRegister")
    public R register(@RequestBody MemberVo memberVo){
        return memberFeign.register(memberVo);
    }

    public R fallBackRegister(@RequestBody MemberVo memberVo){
        return new R(404, "服务器繁忙，请稍后再试", null);
    }
}
